﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Prolog
{
    public partial class Form1 : Form
    {
        ConnectProlog con;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //con = new ConnectProlog();
            List<string> content = BasicFunction.File_ReadFile(Application.StartupPath + @"\txt Tu Vung.pl");
            txtbx_tuvung.Text = "";
            foreach (string line in content)
                txtbx_tuvung.Text += line + "\r\n";

            content = BasicFunction.File_ReadFile(Application.StartupPath + @"\txt Ngu Phap.pl");
            txtbx_nguphap.Text = "";
            foreach (string line in content)
                txtbx_nguphap.Text += line + "\r\n";

            content = BasicFunction.File_ReadFile(Application.StartupPath + @"\txt Ham.pl");
            txtbx_ham.Text = "";
            foreach (string line in content)
                txtbx_ham.Text += line + "\r\n";
        }

        private void btt_biendich_Click(object sender, EventArgs e)
        {  
            /// Biên dịch phần hàm trước sau đó mới đến từ vựng và ngữ pháp.           
            BasicFunction.File_WriteFile(Application.StartupPath + @"\txt Ham.pl", BasicFunction.GetListString(txtbx_ham.Text));
            BasicFunction.File_WriteFile(Application.StartupPath + @"\txt Tu Vung.pl", BasicFunction.GetListString(txtbx_tuvung.Text));
            BasicFunction.File_WriteFile(Application.StartupPath + @"\txt Ngu Phap.pl", BasicFunction.GetListString(txtbx_nguphap.Text));

            con = new ConnectProlog();
            con.InputFile(Application.StartupPath + @"\txt Ham.pl");
            con.InputFile(Application.StartupPath + @"\txt Tu Vung.pl");
            con.InputFile(Application.StartupPath + @"\txt Ngu Phap.pl");
        }

        private void btt_truyvan_Click(object sender, EventArgs e)
        {
            string result = con.Result(txtbx_truyvan.Text);
            txtbx_ketquatruyvan.Text = result;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string text = "trần nguyên phò";
            Replay rep = new Replay();
            string prolog = rep.ConvertTiengVietToProlog(text);
            string tiengviet = rep.ConvertPrologToTiengViet(prolog);
        }

  
    }
}
